<?php
require_once('../config/config.php') ;

require_once(SYSTEM_PATH.'classes/error'.EXT) ;
require_once(SYSTEM_PATH.'classes/loader'.EXT) ;

Loader::includeClass('cosmo') ;
Loader::includeClass('database/database','core') ;
Loader::includeClass('database/database_driver','core') ;
Loader::includeClass('model') ;
Loader::includeClass('ajaxcontroller') ;
$load 	=& Loader::getInstance() ;
$db 		= new Database() ;
$load->setDatabase($db) ;
if(isset($_GET['c'])) {
	// load the ajax controller
	$ajaxController =& $load->ajaxController($_GET['c']) ;
	if($ajaxController instanceof AjaxController) {
		// object loaded is not an instance of AjaxController, return error to controller
		die('ERROR_CONTROLLER_NOT_EXISTS');
	} elseif(true === $ajaxController->_isError) {
		// an error occured, method required does not exist
		die('ERROR_METHOD_NOT_EXISTS') ;
	}
	echo $ajaxController->_send() ; // display result
} else {
	// no controller called, return an error to controller
	die('ERROR_NO_CONTROLLER') ;
}
?>